package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.RoomInfo;
import com.atguigu.lease.model.enums.ReleaseStatus;
import com.atguigu.lease.web.admin.service.RoomInfoService;
import com.atguigu.lease.web.admin.vo.room.RoomDetailVo;
import com.atguigu.lease.web.admin.vo.room.RoomItemVo;
import com.atguigu.lease.web.admin.vo.room.RoomQueryVo;
import com.atguigu.lease.web.admin.vo.room.RoomSubmitVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 小可乐$ on 2024/8/12$ 21:50$
 * description: 房间信息管理
 */
@Tag(name = "房间信息管理")
@RestController
@RequestMapping("/admin/room")
public class RoomController {
    @Autowired
    private RoomInfoService service;
    /**
     * 根据id修改房间的发布状态
     * */
    @PostMapping("updateReleaseStatusById")
    @Operation(summary = "根据id修改房间的发布状态")
    public Result updateReleaseStatusById(
            @RequestParam Long id,
            @RequestParam ReleaseStatus status) {
        LambdaUpdateWrapper<RoomInfo> roomUpdateWrapper = new LambdaUpdateWrapper<RoomInfo>();
        roomUpdateWrapper.eq(RoomInfo::getId, id);
        roomUpdateWrapper.set(RoomInfo::getIsRelease, status);
        service.update(roomUpdateWrapper);
        return Result.ok();
    }
    /**
     * 保存或更新房间信息
     * */
    @PostMapping("saveOrUpdate")
    @Operation(summary = "保存或更新房间信息")
    public Result saveOrUpdateRoom(@RequestBody RoomSubmitVo submitVo){
        service.saveOrUpdateRoom(submitVo);
        return Result.ok();
    }
    /**
     * 根据条件分页查询房间列表
     * */
    @GetMapping("/pageItem")
    @Operation(summary = "根据条件分页查询房间列表")
    public Result<IPage<RoomItemVo>> PageSelectRoom(@RequestParam Integer current,
                                                    @RequestParam Integer size,
                                                    RoomQueryVo roomQueryVo){
        Page<RoomItemVo> roomItemVoPage = new Page<>(current,size);
        IPage<RoomItemVo> list = service.PageSelectRoom(roomItemVoPage,roomQueryVo);
        return Result.ok(list);
    }
    /**
     * 根据公寓id查询房间列表
     * */
    @GetMapping("listBasicByApartmentId")
    @Operation(summary = "根据公寓id查询房间列表")
    public Result<List<RoomInfo>> listBasicByApartmentId(@RequestParam Long apartmentId){
        LambdaQueryWrapper<RoomInfo> roomQueryWrapper = new LambdaQueryWrapper<>();
        roomQueryWrapper.eq(RoomInfo::getApartmentId,apartmentId);
        List<RoomInfo> list = service.list(roomQueryWrapper);
        return Result.ok(list);
    }

    /**
     * 根据id获取房间详细信息
     * */
    @GetMapping("/getDetailById")
    @Operation(summary = "根据id获取房间详细信息")
    public Result<RoomDetailVo> getDetailById(@RequestParam Long id){
        RoomDetailVo res = service.getDetailById(id);
        return Result.ok(res);
    }

    /**
     * 根据id删除房间信息
     * */
    @DeleteMapping("removeById")
    @Operation(summary = "根据id删除房间信息")
    public Result removeById(@RequestParam Long id){
        service.removeRoomById(id);
        return Result.ok();
    }

}

